﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ViCode_LeVi.KeyGen
{
    public static class KeyGenHelper
    {
        private static string _PATHKEY;
        private static string PATHKEY
        {
            get 
            {
                if (string.IsNullOrEmpty(_PATHKEY))
                {
                    _PATHKEY = System.IO.Path.GetTempPath() + "/swisscsg.lic";
                }
                return _PATHKEY;
            }
        }
        private static string[] Keys = new string[] 
        {
            "1K3H5N2B7L2N",
            "2K5H8A9S7D6F",
            "6S8D9S6F5C5A",
            "5F4S7G8S4A1A",
            "7F5D8H5I3T9G",
            "5G5D2S1A4D7U",
            "3H5B6K9O5P1Q",
            "5D4F7A4S1T2Y",
            "5G2D5S4A7W9Q",
            "3A5S8F7M4B9F",
            "2D5S8A2T1U3I",
            "5D8F7G6A8F7A"
        };
        public static bool CheckKey()
        {
            try
            {
                if (System.IO.File.Exists(PATHKEY))
                {
                    string s = System.IO.File.ReadAllText(PATHKEY);
                    return Keys.Contains(s);
                }
            }
            catch { }
            return InputKey();
        }
        public static bool InputKey()
        {
            Window_InputKey w = new Window_InputKey();
            w.ShowDialog();
            return true;
        }
        public static bool InputKey(string key)
        {
            if (Keys.Contains(key))
            {
                //if (!System.IO.File.Exists(PATHKEY))
                //    System.IO.File.CreateText(PATHKEY);
                //if (System.IO.File.Exists(PATHKEY))
                FileFolder.FileTextHelper.WriteFile_String_FisrtLine(PATHKEY, key);
                return true;
            }
            return false;
        }
    }
}
